graphs=graph_ac.png graph_tran.png

all:netlist simulation

netlist:$(patsubst graph_%.png,output_%.net,$(graphs))

simulation:$(graphs) $(patsubst graph_%.png,rawspice_%.raw,$(graphs))

graph_%.png:rawspice_%.raw graph.m
	octave -q --eval 'graph("$(patsubst graph_%.png,%,$@)")'

rawspice_%.raw:output_%.net
	ngspice -b $< -r $@

%.net:%.net.tmp
	sed -e 's/*\(.$(patsubst output_%.net,%,$@)\)/\1/g' $< > $@

output_%.net.tmp:simulation.cmd ecg.sch Body_potential.sch ecgsyn.ckt TL071.mod
	gnetlist -g spice-sdb -e ecg.sch Body_potential.sch -o $@

clean:
	rm -f *.tmp



